#include "timer.h"
#include "SDL2/SDL.h"

cTimer::cTimer()
{
    m_startTicks = 0;
    m_pausedTicks = 0;
    m_paused = false;
    m_started = false;
}

void cTimer::start()
{
    m_started = true;
    m_paused = false;

    m_startTicks = SDL_GetTicks();
}

void cTimer::stop()
{
    m_started = false;
    m_paused = false;
}

void cTimer::pause()
{
    if((m_started == true) && (m_paused == false))
    {
        m_paused = true;

        m_pausedTicks = SDL_GetTicks() - m_startTicks;
    }
}

void cTimer::unPause()
{
    if(m_paused == true)
    {
        m_paused = false;

        m_startTicks = SDL_GetTicks() - m_pausedTicks;

        m_pausedTicks = 0;
    }
}

int cTimer::getTicks()
{
    if(m_started == true)
    {
        if(m_paused == true)
        {
            return m_pausedTicks;
        }
        else
        {
            return SDL_GetTicks() - m_startTicks;
        }
    }

    return 0;
}

bool cTimer::started()
{
    return m_started;
}

bool cTimer::paused()
{
    return m_paused;
}
